/// @tags: DPwithNumber
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long LL;
int const N = 1e4 + 5, mod = 1e6 + 7;

int n, ans = 1, a[N];
long long f[2][N][2];

inline int main() {
  cin >> n;
  f[1][1][1] = 1;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j <= i; ++j) {
      int cur = i & 1, nxt = cur ^ 1;
      if ((f[nxt][j][0] += (LL)f[cur][j][0] * j % mod) >= mod) f[nxt][j][0] -= mod;
      if ((f[nxt][j + 1][0] += f[cur][j][0]) >= mod) f[nxt][j + 1][0] -= mod;
      if ((f[nxt][j][0] += (LL)f[cur][j][1] * (a[i + 1] - 1) % mod) >= mod)
        f[nxt][j][0] -= mod;
      ((a[i + 1] == j + 1 ? f[nxt][j + 1][1] : f[nxt][j][1]) += f[cur][j][1]) %= mod;
      f[cur][j][0] = f[cur][j][1] = 0;
    }
  }
  for (int i = n, j = 1; j <= n; ++j) {
    ans += f[i & 1][j][0];
    if (ans >= mod) ans -= mod;
  }
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4798 [CEOI2015 Day1] 卡尔文球锦标赛.in", "r", stdin);
  freopen("P4798 [CEOI2015 Day1] 卡尔文球锦标赛.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
